<template>
	<div class="portal_edit_container" v-loading="loading">
		<div class="button">
			<el-button class="cancel" size="small" @click="handleHeaderBack()">取消</el-button>
			<el-button class="confirm" size="small" type="primary" @click="handleSubmitForm()">确认</el-button>
		</div>
		<el-page-header @back="handleHeaderBack()" :content="`修改站点 - ${portalData.name}`"></el-page-header>
		<site-form ref="form" :data="portalData" :is-edit="true"></site-form>
	</div>
</template>

<script>
import siteMixins from './mixins';
import { getPortalSiteBaseInfo } from '@/api/portal/tbSiteInfo';
export default {
	mixins: [siteMixins],
	data() {
		return {
			loading: false
		};
	},
	computed: {
		siteId() {
			return this.$route.query.id;
		}
	},
	watch: {
		siteId: {
			handler(id) {
				this.getPortalBaseInfo(id);
			},
			immediate: true
		}
	},
	methods: {
		//获取站点信息
		async getPortalBaseInfo(id) {
			let result = await getPortalSiteBaseInfo(id).then(res => res.data);
			if(result.code === '0') {
				let datas = !!result.data && result.data.length > 0 ? result.data[0] : {};
				let userList = !datas.userMList ? [] : datas.userMList.map(async item => {
					let obj = { relId: item.userId, relName: item.userName };
					obj['picAttr'] = !!item.picId && item.picId !== '-1' ? await this.getFileUrl(item.picId) : this.defaultImage;
					return obj;
				})
				this.portalData = { ...datas, userList: await Promise.all(userList) };
			}
		},

		//提交
		handleSubmitForm(data) {
			this.$refs['form'].submitForm();
		}
	}
};
</script>

<style lang="scss" scoped>
.portal_edit_container::v-deep {
	display: flex;
	flex-direction: column;
	height: 100%;
	position: relative;
	overflow: hidden;

	.el-page-header {
		padding: 16px;
		border-bottom: solid 1px #EBEEF5;
	}

	.el-form {
		flex: 1;
		overflow: auto;
	}

	.button {
		position: absolute;
		top: 12px;
		right: 12px;
	}
}
</style>